package views.user.report

import tool.ReportPojo.ReportData

/**
 * Created by Administrator on 2019/12/18
 */
object IndexTool {

  def getIPathImageIndex(i: Int)(implicit data: ReportData) = {
    var index = getHeatmapImageIndex(i)
    if (data.configDatas(i).isIPathExec) {
      index += 1
    }

    if (data.configDatas(i).groups.size > 2) {
      index -= 4
    }
    index
  }

  def getPotentialImageIndex(i: Int)(implicit data: ReportData) = {
    val index = if (data.resultDatas(i).uniDiffSize == 0) {
      1
    } else 2
    index + 6
  }

  def getHeatmapImageIndex(i: Int)(implicit data: ReportData) = {
    getPotentialImageIndex(i) + 1
  }

  def getCsSelfCorIndex(i: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isEnrichExec) {
      1
    } else 0
    index + 1
  }

  def getCsUploadCorIndex(i: Int)(implicit data: ReportData) = {
    getCsSelfCorIndex(i) + 1
  }

  def getCsParCorIndex(i: Int)(implicit data: ReportData) = {
    getCsUploadCorIndex(i) + 1
  }

  def getEnrichImageIndex(i: Int, j: Int)(implicit data: ReportData) = {
    val libTypeAbbr = data.configDatas(i).libTypesAbbr(j)
    val allExistAbbrs =data.configDatas(i).libTypesAbbr.map{abbr=>
      (abbr,data.resultDatas(i).hasEnrichMap.getOrElse(abbr,false))
    }.filter(_._2).map(_._1)
    val finalJ = allExistAbbrs.indexOf(libTypeAbbr)
    val index = if (data.configDatas(i).isEnrichExec) {
      finalJ + 1
    } else 0
    index + getIPathImageIndex(i)
  }

  def getPathwayImageIndex(i: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isPathwayExec && data.resultDatas(i).hasBubble) {
      1
    } else 0
    val j = data.configDatas(i).libTypesAbbr.map{abbr=>
     data.resultDatas(i).hasEnrichMap.getOrElse(abbr,false)
    }.zipWithIndex.findLast(_._1).map(_._2).getOrElse(0)
    index + getEnrichImageIndex(i, j)
  }

  def getCorImageIndex(i: Int, j: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isCor) {
      j + 1
    } else 0
    index + getPathwayImageIndex(i)
  }

  def getParCorImageIndex(i: Int, j: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isParCor) {
      j + 1
    } else 0
    val inJ = data.outerData.extraDatas.size - 1
    index + getCorImageIndex(i, inJ)
  }

  def getDiagnoseImageIndex(i: Int, j: Int)(implicit data: ReportData) = {
    val index = j + 1
    val inJ = data.outerData.extraDatas.size - 1
    index + getParCorImageIndex(i, inJ)
  }

  def getAndDir(i: Int)(implicit data: ReportData) = {
    (data.treats(i).replace("_vs_", "_and_"))
  }

  def getParCor2Index(i: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isParCor) {
      1
    } else 0
    index + getCor2Index(i)
  }

  def getCor2Index(i: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isCor || data.configDatas(i).isSelfCor || data.configDatas(i).isParCor) {
      1
    } else 0
    index + getPathway2Index(i)
  }

  def getPathway2Index(i: Int)(implicit data: ReportData) = {
    if (data.configDatas(i).isIPathExec || data.configDatas(i).isEnrichExec || data.configDatas(i).isPathwayExec) {
      5
    } else 4
  }

  def getDiagnose2Index(i: Int)(implicit data: ReportData) = {
    val index = if (data.configDatas(i).isDiagnoseExec) {
      1
    } else 0
    index + getParCor2Index(i)
  }


}
